package com.xuxiao.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author xuxiao
 */
@Component
public class SpringPublisherForError  {

    @Autowired
    SimpleApplicationEventMulticaster applicationEventMulticaster;

    private void publishEventError(SpringEventForError springEventForError){
        applicationEventMulticaster.multicastEvent(springEventForError);
    }

    private void publishEventMessage(SpringEventForMessage springEventForMessage){
        applicationEventMulticaster.multicastEvent(springEventForMessage);
    }


    public void publishEventError(Throwable throwable){
        SpringEventForError springEventForError = new SpringEventForError(throwable, throwable.getMessage());
        publishEventError(springEventForError);
    }
    public void publishEventMessage(Map<String,Object> table){
        SpringEventForMessage springEventForError = new SpringEventForMessage(table, table.toString());
        publishEventMessage(springEventForError);
    }
}
